import axios from 'axios'
import store from '../../store'
import router from '../../router'
import {Message} from 'element-ui';

axios.defaults.baseURL = 'api/'
axios.defaults.headers.post['Content-Type'] = 'application/json'
axios.defaults.method = "post"
axios.defaults.timeout = 5000;

export default (url, data, callback, successCallBack, isAction = false) => {
    axios.post(url, data
    ).then(response => {
        callback()
        if (response.data.resultCode === '1') {

            successCallBack(response.data.content)
            if(isAction)
            {
                Message({
                    message: "成功",
                    type: 'success'
                })
            }
        }
        else if (response.data.resultCode === '10021007') {
            store.commit('setUserInfo', null)
            router.push('/login')
        }
        else {
            Message({
                message: response.data.resultMsg,
                type: 'error'
            })
        }

    }).catch(function (error) {
        callback()
        Message({
            message: "系统繁忙，请重试",
            type: 'error'
        })
    });
}
